package com.park.controller;

import com.alibaba.fastjson.JSON;
import com.park.entity.Recharge;
import com.park.service.RechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class RechargeController {

    @Autowired
    private RechargeService rs;

    @GetMapping("/parking/rechargeAdd")
    @ResponseBody
    public String addRecharge(@RequestParam("rechargeUserId")int rechargeUserId, @RequestParam("rechargeUserName")String rechargeUserName, @RequestParam("rechargeCarId")String rechargeCarId, @RequestParam("rechargeAmount")double rechargeAmount){
        Recharge recharge=new Recharge();
        recharge.setRechargeUserId(rechargeUserId);
        recharge.setRechargeUserName(rechargeUserName);
        recharge.setRechargeCarId(rechargeCarId);
        recharge.setRechargeAmount(rechargeAmount);
        Map<String,String> map=new HashMap<String,String>();
        int result=rs.addRecharge(recharge);
        if(result==1) {
            map.put("addResult","true");
        }else {
            map.put("addResult","false");
        }
        return JSON.toJSONString(map);
    }
}
